const { Sequelize, Model, DataTypes } = require("sequelize");
const sequelize = require("../utils/sequelize");

// 用户
const Users = sequelize.define(
  "Users",
  {
    username: DataTypes.STRING,
    nick: {
      type: DataTypes.STRING,
      defaultValue: "nick",
    },
    password: DataTypes.STRING,
    mobile: DataTypes.STRING,
    code: DataTypes.INTEGER,
    createDate: {
      type: Sequelize.DATE,
      defaultValue: Sequelize.NOW,
    },
    userid: {
      type: DataTypes.STRING,
      primaryKey: true,
    },
    sex: DataTypes.INTEGER,
    tag: DataTypes.STRING,
    headerurl: DataTypes.STRING,
    status: {
      type: DataTypes.INTEGER,
      defaultValue: 1,
    },
    nosay: {
      type: DataTypes.INTEGER,
      defaultValue: 1,
    },
  },
  {
    timestamps: false,
    freezeTableName: true,
  }
);

// 发布
const Pubilc = sequelize.define(
  "User_public",
  {
    title: DataTypes.STRING,
    describe: {
      type: DataTypes.STRING,
      defaultValue: "描述",
    },
    url: DataTypes.STRING,
    header_url: DataTypes.STRING,
    stars: DataTypes.INTEGER,
    createDate: {
      type: Sequelize.DATE,
      defaultValue: Sequelize.NOW,
    },
    username: DataTypes.STRING,
    userid: DataTypes.STRING,
    love_nums: DataTypes.INTEGER,
    r_price: DataTypes.INTEGER,
    c_price: DataTypes.INTEGER,
    urllist: {
      type: DataTypes.STRING,
      defaultValue: "",
    },
    cao: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
    },
    nao: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
    },
  },
  {
    timestamps: false,
    freezeTableName: true,
  }
);

// 评论
const Comment = sequelize.define(
  "Comment",
  {
    username: DataTypes.STRING,
    headerurl: DataTypes.STRING,
    userid: DataTypes.STRING,
    publicid: DataTypes.INTEGER,
    createDate: {
      type: Sequelize.DATE,
      defaultValue: Sequelize.NOW,
    },
    content: DataTypes.STRING,
  },
  {
    timestamps: false,
    freezeTableName: true,
  }
);

// 状态
const Status = sequelize.define(
  "Status",
  {
    userid: DataTypes.STRING,
    publicid: DataTypes.STRING,
    iszc: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
    },
    isnz: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
    },
    iscollect: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
    },
    iszan: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
    },
    createDate: {
      type: Sequelize.DATE,
      defaultValue: Sequelize.NOW,
    },
  },
  {
    timestamps: false,
    freezeTableName: true,
  }
);

// 地址
const Address = sequelize.define(
  "Address",
  {
    userid: DataTypes.STRING,
    name: DataTypes.STRING,
    tel: DataTypes.STRING,
    province: DataTypes.STRING,
    city: DataTypes.STRING,
    county: DataTypes.STRING,
    addressDetail: DataTypes.STRING,
    areaCode: DataTypes.STRING,
    isDefault: {
      type: DataTypes.INTEGER,
      defaultValue: true,
    },
  },
  {
    timestamps: false,
    freezeTableName: true,
  }
);

// 好友
const Friend = sequelize.define(
  "Friend",
  {
    userid: DataTypes.STRING, //自己id
    addid: DataTypes.STRING, //被添加id
    username: DataTypes.STRING, //自己用户名
    addname: DataTypes.STRING, //被添加用户名
    myheaderurl: DataTypes.STRING, //自己头像
    headerurl: DataTypes.STRING, //被添加用户头像
    nick: DataTypes.STRING, //被添用户昵称
    mynick: DataTypes.STRING, //自己昵称
    status: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
    },
  },
  {
    timestamps: false,
    freezeTableName: true,
  }
);

// 获取电影列表
const Videos = sequelize.define(
  "Video",
  {
    videoid: DataTypes.STRING,
    type: DataTypes.STRING,
    url: DataTypes.STRING,
    title: DataTypes.STRING,
    info: DataTypes.STRING,
    episode: DataTypes.STRING,
    language: {
      type: DataTypes.STRING,
      defaultValue: "国语",
    },
    pyear: DataTypes.STRING,
    createTime: {
      type: Sequelize.DATE,
      defaultValue: Sequelize.NOW,
    },
  },
  {
    timestamps: false,
    freezeTableName: true,
  }
);

module.exports = {
  Users: Users,
  Pubilc: Pubilc,
  Comment: Comment,
  Status: Status,
  Address: Address,
  Friend: Friend,
  Videos: Videos,
};
